package com.qfedu.item.controller;

import com.qfedu.item.domain.User;
import com.qfedu.item.response.Response;
import com.qfedu.item.service.intf.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

@RestController
@RequestMapping("user")
@RequiredArgsConstructor
public class UserController {
    //推荐使用
    private final UserService service;

    @PostMapping("login")
    public Response<User> login(@RequestBody User user){
         User login = service.Login(user.getUsername(), user.getPassword());
        if (StringUtils.isEmpty(login)) {
            return Response.fail();
        } else {
            return Response.success(login);
        }
//       if (StringUtils.isEmpty(login)){
//             return Response.fail();
//         }else {
//            return Response.success(login);
//        }

    }

    @GetMapping("like")
    public Response<User> likes(Integer userId, Integer cardId, Boolean like){
        User user = service.likeCard(userId, cardId, like);
        return Response.success(user);
    };
}
